﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI.DataPartLib
{
    public partial class DataChartSector
    {
        public static DependencyProperty ValueLabelLeftProperty = DependencyProperty.Register("ValueLabelLeft", typeof(int), typeof(DataChartSector), null);
        public int ValueLabelLeft
        {
            get { return (int)GetValue(ValueLabelLeftProperty); }
            set { SetValue(ValueLabelLeftProperty, value); }
        }

        public static DependencyProperty ValueLabelTopProperty = DependencyProperty.Register("ValueLabelTop", typeof(double), typeof(DataChartSector), null);
        public int ValueLabelTop
        {
            get { return (int)GetValue(ValueLabelTopProperty); }
            set { SetValue(ValueLabelTopProperty, value); }
        }

        public static DependencyProperty DataItemValueProperty = DependencyProperty.Register("DataItemValue", typeof(string), typeof(DataChartSector), null);
        public string DataItemValue
        {
            get { return (string)GetValue(DataItemValueProperty); }
            set { SetValue(DataItemValueProperty, value); }
        }

        public static DependencyProperty DataItemNameProperty = DependencyProperty.Register("DataItemName", typeof(string), typeof(DataChartSector), null);
        public string DataItemName
        {
            get { return (string)GetValue(DataItemNameProperty); }
            set { SetValue(DataItemNameProperty, value); }
        }

        public static DependencyProperty IndexValueProperty = DependencyProperty.Register("IndexValue", typeof(int), typeof(DataChartSector), null);
        public int IndexValue
        {
            get { return (int)GetValue(IndexValueProperty); }
            set { SetValue(IndexValueProperty, value); }
        }

        public static DependencyProperty FillBrushProperty = DependencyProperty.Register("FillBrush", typeof(Brush), typeof(DataChartSector), null);
        public Brush FillBrush
        {
            get { return (Brush)GetValue(FillBrushProperty); }
            set { SetValue(FillBrushProperty, value); }
        }
        private static void OnFillBrushPropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataChartSector sector = d as DataChartSector;
            if(e.NewValue != null)
            {
                sector.arcSector.Fill = (Brush)e.NewValue;
            }
        }

        public static DependencyProperty ArcStartAngleProperty = DependencyProperty.Register("ArcStartAngle", typeof(double), typeof(DataChartSector), null);
        public double ArcStartAngle
        {
            get { return (double)GetValue(ArcStartAngleProperty); }
            set { SetValue(ArcStartAngleProperty, value); }
        }
        private static void OnArcStartAnglePropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataChartSector sector = d as DataChartSector;

            if (e.NewValue != null)
            {
                double newValue = Convert.ToDouble(e.NewValue);
                sector.arcRing.StartAngle = newValue;
            }
        }
        public static DependencyProperty ArcEndAngleProperty = DependencyProperty.Register("ArcEndAngle", typeof(double), typeof(DataChartSector), new PropertyMetadata(OnArcEndAnglePropertyChange));
        public double ArcEndAngle
        {
            get { return (double)GetValue(ArcEndAngleProperty); }
            set { SetValue(ArcEndAngleProperty, value); }
        }
        private static void OnArcEndAnglePropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataChartSector sector = d as DataChartSector;

            if (e.NewValue != null)
            {
                if (sector.arcSector.StartAngle + sector.OffsetAngle == Convert.ToDouble(e.NewValue))
                {
                    if (sector.IsLineVisible)
                        sector.LineVisible = Visibility.Visible;
                    if (sector.IsItemNameVisible)
                        sector.ItemNameVisible = Visibility.Visible;
                    if (sector.IsItemValueVisible)
                        sector.ItemValueVisible = Visibility.Visible;

                    sector.indexLabel.Visibility = Visibility.Visible;
                }
            }
        }

        public static DependencyProperty ArcMiddleAngleProperty = DependencyProperty.Register("ArcMiddleAngle", typeof(double), typeof(DataChartSector), null);
        public double ArcMiddleAngle
        {
            get { return (double)GetValue(ArcMiddleAngleProperty); }
            set { SetValue(ArcMiddleAngleProperty, value); }
        }

        public static DependencyProperty ArcNegativeMiddleAngleProperty = DependencyProperty.Register("ArcNegativeMiddleAngle", typeof(double), typeof(DataChartSector), null);
        public double ArcNegativeMiddleAngle
        {
            get { return (double)GetValue(ArcNegativeMiddleAngleProperty); }
            set { SetValue(ArcNegativeMiddleAngleProperty, value); }
        }

        public static DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(DataChartSector), null);
        public double CenterX
        {
            get { return (double)GetValue(CenterXProperty); }
            set { SetValue(CenterXProperty, value); }
        }
        public static DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(DataChartSector), null);
        public double CenterY
        {
            get { return (double)GetValue(CenterYProperty); }
            set { SetValue(CenterYProperty, value); }
        }

        public static DependencyProperty ValueLabelPaddingProperty = DependencyProperty.Register("ValueLabelPadding", typeof(Thickness), typeof(DataChartSector), null);
        public Thickness ValueLabelPadding
        {
            get { return (Thickness)GetValue(ValueLabelPaddingProperty); }
            set { SetValue(ValueLabelPaddingProperty, value); }
        }

        public static DependencyProperty SectorWidthProperty = DependencyProperty.Register("SectorWidth", typeof(double), typeof(DataChartSector), null);
        public double SectorWidth
        {
            get { return (double)GetValue(SectorWidthProperty); }
            set { SetValue(SectorWidthProperty, value); }
        }

        public static DependencyProperty SectorHeightProperty = DependencyProperty.Register("SectorHeight", typeof(double), typeof(DataChartSector), null);
        public double SectorHeight
        {
            get { return (double)GetValue(SectorHeightProperty); }
            set { SetValue(SectorHeightProperty, value); }
        }

        public static DependencyProperty SectorMarginProperty = DependencyProperty.Register("SectorMargin", typeof(Thickness), typeof(DataChartSector), null);
        public Thickness SectorMargin
        {
            get { return (Thickness)GetValue(SectorMarginProperty); }
            set { SetValue(SectorMarginProperty, value); }
        }
        
        public double OffsetAngle
        {
            get; set;
        }


        public static DependencyProperty LineVisibleProperty = DependencyProperty.Register("LineVisible", typeof(Visibility), typeof(DataChartSector), null);
        public Visibility LineVisible
        {
            get { return (Visibility)Enum.Parse(typeof(Visibility), GetValue(LineVisibleProperty).ToString()); }
            set { SetValue(LineVisibleProperty, value); }
        }

        public static DependencyProperty ItemNameVisibleProperty = DependencyProperty.Register("ItemNameVisible", typeof(Visibility), typeof(DataChartSector), null);
        public Visibility ItemNameVisible
        {
            get { return (Visibility)Enum.Parse(typeof(Visibility), GetValue(ItemNameVisibleProperty).ToString()); }
            set { SetValue(ItemNameVisibleProperty, value); }
        }

        public static DependencyProperty ItemValueVisibleProperty = DependencyProperty.Register("ItemValueVisible", typeof(Visibility), typeof(DataChartSector), null);
        public Visibility ItemValueVisible
        {
            get { return (Visibility)Enum.Parse(typeof(Visibility), GetValue(ItemValueVisibleProperty).ToString()); }
            set { SetValue(ItemValueVisibleProperty, value); }
        }

        public bool IsLineVisible { get; set; }
        public bool IsItemNameVisible { get; set; }
        public bool IsItemValueVisible { get; set; }


    }
}
